# 判断矩阵是否是方阵

def is_upper_triangular (arr, n):
  for i in range(1,n):
    for j in range(i):
      if (arr[i][j] != 0):
        return False
  return True

def is_lower_triangular (arr, n):
  for i in range(1,n):
    for j in range(i):
      if (arr[j][i] != 0):
        return False
  return True

total = int(input())

while total>0:
  total -= 1
  n = int(input())
  arr = []
  for i in range(n):
    arr.append([])
    s = input().split()
    for j in range(n):
      arr[i].append(int(s[j]))
  if (is_lower_triangular(arr, n)):
    print('lower triangular matrix')
  elif (is_upper_triangular(arr, n)):
    print('upper triangular matrix')
  else:
    print('no')
  
